<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="真实姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入真实姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系方式" prop="contact">
        <el-input
          v-model="queryParams.contact"
          placeholder="请输入联系方式"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker
          v-model="daterangeSubmitTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="是否批注成功" prop="canAnnotate">
        <el-select v-model="queryParams.canAnnotate" placeholder="请选择是否" clearable>
          <el-option
            v-for="dict in dict.type.bole_remark"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="分组编号" prop="groupNum">
        <el-input
          v-model="queryParams.groupNum"
          placeholder="请输入分组编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker
          v-model="daterangeUpdateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="opt in [0,1,2,3,4]"
            :key="opt"
            :label="statusType[opt]"
            :value="opt"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="分配工作量" prop="workload">
        <el-input
          v-model="queryParams.workload"
          placeholder="请输入分配工作量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['remark:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['remark:project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['remark:project:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['remark:project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键ID" align="center" prop="submitId" /> -->
      <el-table-column label="真实姓名" align="center" prop="name" />
      <el-table-column label="学号" align="center" prop="studentId" />
      <el-table-column label="联系方式" align="center" prop="contact" />
      <el-table-column label="时间" align="center" prop="submitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件标题" align="center" prop="title" />
      <el-table-column label="工作文件" align="center" prop="workFile" />
      <el-table-column label="是否标注成功" align="center" prop="canAnnotate">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bole_remark" :value="scope.row.canAnnotate"/>
        </template>
      </el-table-column>
      <el-table-column label="不可原因" align="center" prop="cause" />
      <el-table-column label="分组编号" align="center" prop="groupNum" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <div>
            <el-tag v-if="scope.row.status == 0" size="small">组长审核中</el-tag>
            <el-tag v-if="scope.row.status == 1" size="small">团长审核中</el-tag>
            <el-tag v-if="scope.row.status == 2" size="small">负责人审核中</el-tag>
            <el-tag v-if="scope.row.status == 3" size="small"  type="success">已通过</el-tag>
              <el-tag type="danger" v-if="scope.row.status == 4" size="small">已拒绝</el-tag>
          </div>
          <!-- <dict-tag :options="dict.type.bole_event_registration" :value="scope.row.status"/> -->
        </template>
      </el-table-column>
      <el-table-column label="分配工作量" align="center" prop="workload" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['remark:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['remark:project:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改标注提交记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="真实姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="学号" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="联系方式" prop="contact">
          <el-input v-model="form.contact" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="提交时间" prop="submitTime">
          <el-date-picker clearable
            v-model="form.submitTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作文件路径" prop="workFile">
          <file-upload v-model="form.workFile"/>
        </el-form-item>
        <el-form-item label="是否批注成功" prop="canAnnotate">
          <el-select v-model="form.canAnnotate" placeholder="请选择是否">
            <el-option
              v-for="dict in dict.type.bole_remark"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="不可原因" prop="cause">
          <el-input v-model="form.cause" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="分组编号" prop="groupNum">
          <el-input v-model="form.groupNum" placeholder="请输入分组编号" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
          
              <el-radio label="0">组长审核中</el-radio>
              <el-radio label="1">团长审核中</el-radio>
               <el-radio label="2">负责人审核中</el-radio>
              <el-radio label="3">通过</el-radio>
 <el-radio label="4">拒绝</el-radio>

          </el-radio-group>
        </el-form-item>
        <el-form-item label="分配工作量" prop="workload">
          <el-input v-model="form.workload" placeholder="请输入分配工作量" />
        </el-form-item>
        <el-form-item label="用户ID，关联 sys_user 表的 user_id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID，关联 sys_user 表的 user_id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/remark/project";

export default {
  name: "Project",
  dicts: ['bole_event_registration', 'bole_remark'],
  data() {
    return {
      //审核状态
      statusType: {
        0: "组长审核中",
        1: "团长审核中",
        2: "项目负责人审核中",
        3: "全部通过",
        4: "审核未通过"
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标注提交记录表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户ID，关联 sys_user 表的 user_id时间范围
      daterangeSubmitTime: [],
      // 用户ID，关联 sys_user 表的 user_id时间范围
      daterangeUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        studentId: null,
        contact: null,
        submitTime: null,
        workFile: null,
        canAnnotate: null,
        cause: null,
        groupNum: null,
        updateTime: null,
        status: null,
        workload: null,
        userId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "真实姓名不能为空", trigger: "blur" }
        ],
        studentId: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        groupNum: [
          { required: true, message: "分组编号不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户ID，关联 sys_user 表的 user_id不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询标注提交记录列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSubmitTime && '' != this.daterangeSubmitTime) {
        this.queryParams.params["beginSubmitTime"] = this.daterangeSubmitTime[0];
        this.queryParams.params["endSubmitTime"] = this.daterangeSubmitTime[1];
      }
      if (null != this.daterangeUpdateTime && '' != this.daterangeUpdateTime) {
        this.queryParams.params["beginUpdateTime"] = this.daterangeUpdateTime[0];
        this.queryParams.params["endUpdateTime"] = this.daterangeUpdateTime[1];
      }
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        submitId: null,
        name: null,
        studentId: null,
        contact: null,
        submitTime: null,
        workFile: null,
        canAnnotate: null,
        cause: null,
        groupNum: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        status: null,
        workload: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSubmitTime = [];
      this.daterangeUpdateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.submitId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加标注提交记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const submitId = row.submitId || this.ids
      getProject(submitId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改标注提交记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.submitId != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const submitIds = row.submitId || this.ids;
      this.$modal.confirm('是否确认删除标注提交记录编号为"' + submitIds + '"的数据项？').then(function() {
        return delProject(submitIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('remark/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
